import request from '@/utils/request'
import {parseStrEmpty} from '@/utils/ruoyi'

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/rabc/v1/user/page',
    method: 'post',
    data: query
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/rabc/v1/user/' + parseStrEmpty(userId),
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/rabc/v1/user?google_code=' + data.google_code,
    method: 'post',
    data: data
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/rabc/v1/user?google_code=' + data.google_code,
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function resetUserPwd(id, password, google_code) {
  const data = {
    id,
    password
  }
  return request({
    url: '/uc/v1/reset_pwd/admin?google_code=' + google_code,
    method: 'post',
    data: data
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/customer/v1/user/profile',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/customer/v1/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(old_password, password) {
  const data = {
    old_password,
    password
  }
  return request({
    url: '/uc/v1/auth/reset_pwd',
    method: 'post',
    data: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/rabc/api/user/profile/avatar',
    method: 'post',
    data: data
  })
}

// 查询授权角色
export function getAuthRole(userId) {
  return request({
    url: '/rabc/v1/user/' + userId + '/role',
    method: 'get'
  })
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/rabc/v1/user/role',
    method: 'put',
    data: data
  })
}
